<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>预约管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <!--日历模版-->
                <el-date-picker
                        v-model="pagination.queryTime"
                        type="daterange"
                        align="right"
                        unlink-panels
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :picker-options="pickerOptions">
                </el-date-picker>
                <!--预约类型-->
                <el-select v-model="pagination.orderType" clearable placeholder="预约类型">
                    <el-option
                            v-for="item in orderTypeOptions"
                            :key="item.orderType"
                            :label="item.label"
                            :value="item.orderType">
                    </el-option>
                </el-select>
                <!--支付状态-->
                <el-select v-model="pagination.pay" clearable placeholder="支付状态">
                    <el-option
                            v-for="item in payStatusOptions"
                            :key="item.pay"
                            :label="item.label"
                            :value="item.pay">
                    </el-option>
                </el-select>
                <!--<el-input placeholder="预约类型" v-model="pagination.orderType"  style="width: 200px;" class="filter-item"></el-input>-->
                <!--<el-input placeholder="支付状态" v-model="pagination.pay"  style="width: 200px;" class="filter-item"></el-input>-->
                <el-input placeholder="身份证/手机号/姓名" v-model="pagination.queryString"  style="width: 200px;" class="filter-item"></el-input>
                <el-button @click="pagination.currentPage = 1;findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center">
                </el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="setmealName" label="套餐名称" align="center"></el-table-column>
                    <el-table-column prop="status" label="到诊状态">
                        <template slot-scope="scope">
                            <el-switch
                                    active-color="#13ce66"
                                    inactive-color="#ff4949"
                                    v-model="scope.row.status"
                                    active-text="已到诊"
                                    inactive-text="未到诊"
                                    active-value="1"
                                    inactive-value="0"
                                    @change="change(scope.row)"
                            ></el-switch>
                        </template>
                    </el-table-column>
                <el-table-column prop="pay" label="套餐状态" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.pay == '0' ? '未支付' : '已支付'}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini"
                                   :disabled="scope.row.status==1 ? true : false"
                                   @click="handleUpdate(scope.row)">编辑</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="身份证号">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="出身日期">
                                                <el-date-picker type="date" placeholder="选择日期"
                                                                v-model="formData.birthday" value-format="yyyy-MM-dd"
                                                                style="width: 100%;"></el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号" >
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="不限" value="0"></el-option>
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>

                                        <el-col :span="12">
                                            <el-form-item label="婚姻状况">
                                                <el-select v-model="formData.marry">
                                                    <el-option label="已婚" value="1"></el-option>
                                                    <el-option label="未婚" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="预约时间">
                                                <el-date-picker type="date"
                                                                placeholder="选择日期"
                                                                v-model="formData.orderDate"
                                                                value-format="yyyy-MM-dd"
                                                                style="width: 100%;"></el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12" >
                                            <el-form-item label="预约分校">
                                                <el-select v-model="formData.sortingId" placeholder="请选择分校">
                                                    <el-option
                                                        v-for="item in sorting"
                                                        :key="item.id"
                                                        :label="item.name"
                                                        :value="item.id">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>项目名称</th>
                                            <th>适用人群</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <el-radio :id="c.id" v-model="setmealId" :label="c.id"></el-radio>
                                            </td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.sex== '0' ? '不限' : c.sex == '1' ? '男' : '女'}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑检查项" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="身份证号">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="出身日期">
                                                <el-date-picker type="date" placeholder="选择日期"
                                                                v-model="formData.birthday" value-format="yyyy-MM-dd"
                                                                style="width: 100%;"></el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号" >
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="不限" value="0"></el-option>
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>

                                        <el-col :span="12">
                                            <el-form-item label="婚姻状况">
                                                <el-select v-model="formData.marry">
                                                    <el-option label="已婚" value="1"></el-option>
                                                    <el-option label="未婚" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="预约时间">
                                                <el-date-picker type="date"
                                                                placeholder="选择日期"
                                                                v-model="formData.orderDate"
                                                                value-format="yyyy-MM-dd"
                                                                style="width: 100%;"></el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12" >
                                            <el-form-item label="预约分校">
                                                <el-select v-model="formData.sortingId" placeholder="请选择分校">
                                                    <el-option
                                                            v-for="item in sorting"
                                                            :key="item.id"
                                                            :label="item.name"
                                                            :value="item.id">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐名称</th>
                                            <th>适用人群</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <el-radio :id="c.id" v-model="setmealId" :label="c.id"></el-radio>
                                            </td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.sex == '0' ? '不限' : c.sex == '1' ? '男' :
                                                '女'}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            //预约类型数据
            orderTypeOptions: [{
                //id
                orderType: '微信预约',
                //显示名称
                label: '微信预约'
            }, {
                orderType: '电话预约',
                label: '电话预约'
            }],
            //支付状态数据
            payStatusOptions: [{
                //id
                pay: '1',
                //显示名称
                label: '已支付'
            }, {
                pay: '0',
                label: '未支付'
            }],
            activeName:'first',
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:10,//每页显示的记录数
                total:0,//总记录数
                queryTime:[],
                orderType:null,
                queryString:null,
                pay:null,
            },
            dataList: [],//当前页要展示的分页列表数据
            tableData:[],//新增和编辑表单中对应的套餐项列表数据
            sorting:[],//分院数据
            formData:{},//表单数据
            setmealId:'',//勾选的套餐id
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit:false,//编辑表单是否可见
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage()
        },
        methods: {
            //分页查询
            findPage() {
                if(!this.pagination.queryTime){
                    this.pagination.queryTime=[];
                }
                if(this.pagination.pay=="已支付"){
                    this.pagination.pay='1';
                }

                if(this.pagination.pay=="未支付"){
                    this.pagination.pay='0';
                }
                let params = {
                    currentPage: this.pagination.currentPage,//当前页码
                    pageSize: this.pagination.pageSize,//每页显示的记录数
                    total: this.pagination.total,//总记录数
                    queryString: this.pagination.queryString, //查询条件
                    beginTime: this.pagination.queryTime[0],
                    endTime: this.pagination.queryTime[1],
                    orderType: this.pagination.orderType,
                    pay: this.pagination.pay
                }
                axios.post("/subscribe/findPage",params).then(resp=>{
                    console.log(resp.data);
                    //处理响应结果
                    if(resp.data.flag){
                        //查到了结果
                        // this.$message.success(resp.data.message);
                        //展示表格数据
                        this.dataList=resp.data.data.rows;
                        //展示分页条数据
                        this.pagination.total=resp.data.data.total;
                    }else{
                        this.$message.error(resp.data.message);
                    }
                });
            },

            showMessage(r) {//权限不足提示
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足
                    // this.$message.error('无访问权限');
                    window.location.href = "/error_403.html";
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            },
            //添加
            handleAdd() {
                alert(this.setmealId);
                axios.post("/subscribe/add?setmealId="+this.setmealId,this.formData).then(resp => {
                    this.$message({
                        type:resp.data.flag ? 'success' : 'error',
                        message:resp.data.message
                    });
                    this.dialogFormVisible=false;
                })
                //切换最后一页
                let pages = Math.floor((this.pagination.total + 1) / this.pagination.pageSize);
                let r = (this.pagination.total + 1) % this.pagination.pageSize;
                this.pagination.currentPage = r > 0 ? pages + 1 : pages ;
                //调用分页查询
                this.findPage();
            },

            // 重置表单
            resetForm() {
                this.formData = {};
                this.setmealId="";
            },

            // 弹出添加窗口
            handleCreate() {
                //重置表单数据
                this.resetForm();
                //展示第一个tab标签
                this.activeName = "first";
                //展示新增弹出框
                this.dialogFormVisible = true;
                //发送ajax请求 ,用户点击新增预约时 , 查询所有预约信息
                axios.get("/setMeal/findAll").then(resp => {
                    if (resp.data.flag){
                        //查到了结果
                        //展示表格数据
                        this.tableData=resp.data.data;
                    }else{
                        this.$message.error(resp.data.message);
                    }
                })
                axios.get("/sorting/findAll").then(resp => {
                    if (resp.data.flag){
                        //查到了结果
                        //展示表格数据
                        this.sorting = resp.data.data;
                    }else{
                        this.$message.error(resp.data.message);
                    }
                })
            },

            // 弹出编辑窗口
            handleUpdate(row) {
                this.dialogFormVisible4Edit=true;
                //重置表单数据
                this.resetForm();
                //展示第一个tab标签
                this.activeName = "first";
                //发送ajax请求 ,用户点击新增预约时 , 查询所有预约信息
                axios.get("/setMeal/findAll").then(resp => {
                    if (resp.data.flag){
                        //查到了结果
                        //展示表格数据
                        this.tableData=resp.data.data;
                    }else{
                        this.$message.error(resp.data.message);
                    }
                })
                axios.get("/sorting/findAll").then(resp => {
                    if (resp.data.flag){
                        //查到了结果
                        //展示表格数据
                        this.sorting = resp.data.data;
                    }else{
                        this.$message.error(resp.data.message);
                    }
                })
                axios.get("/subscribe/findById?orderId="+row.id).then(resp=>{
                    console.log(resp.data.data);
                    if (resp.data.flag){
                        //查到了结果
                        //展示表格数据

                        this.formData=resp.data.data;
                        this.setmealId = resp.data.data.setmealId;
                        this.formData.marry = "未婚";
                    }else{
                        this.$message.error(resp.data.message);
                    }
                })
            },

            //编辑
            handleEdit() {
                axios.post("/subscribe/edit?setmealId="+this.setmealId,this.formData).then(resp => {
                    this.$message({
                        type:resp.data.flag ? 'success' : 'error',
                        message:resp.data.message
                    });

                })
                this.dialogFormVisible4Edit=false;
                this.findPage();
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },

            //切换到诊状态id
            change(row){
                let params = {
                    status:row.status,
                    id:row.id
                }
                axios.post("/subscribe/status",params);
            }
        }
    })
</script>
</html>